|  |  | On Wed, 17 Oct 2001 17:22:46 +0100, "Keith Hull"
<kei### [at] totalise co  uk> wrote:
Hi Keith,
just try this:
/*
   Decodes a 3x4 transformation matrix into separate scale, rotation,
   translation, and shear vectors. Based on a program by Spencer W.
   Thomas (Graphics Gems II) and Raw2Pov (Dan Farmer
*/
// input:	mat
// output:	scale, shear, rotate, transl
void decode_matrix (Matrix mat, Vector scale, Vector shear, Vector
rotate,
		Vector transl)
{
	unsigned int i;
	Vector row[3], temp;
	for (i = 0; i < 3; i++)
		transl[i] = mat[3][i];
	for (i = 0; i < 3; i++)
	{
		row[i][0] = mat[i][0];
		row[i][1] = mat[i][1];
		row[i][2] = mat[i][2];
	}
	scale[0] = vect_mag (row[0]);
	vect_normalize (row[0]);
	shear[0] = vect_dot (row[0], row[1]);
	row[1][0] = row[1][0] - shear[0]*row[0][0];
	row[1][1] = row[1][1] - shear[0]*row[0][1];
	row[1][2] = row[1][2] - shear[0]*row[0][2];
	scale[1] = vect_mag (row[1]);
	vect_normalize (row[1]);
	if (scale[1] != 0.0)
		shear[0] /= scale[1];
	shear[1] = vect_dot (row[0], row[2]);
	row[2][0] = row[2][0] - shear[1]*row[0][0];
	row[2][1] = row[2][1] - shear[1]*row[0][1];
	row[2][2] = row[2][2] - shear[1]*row[0][2];
	shear[2] = vect_dot (row[1], row[2]);
	row[2][0] = row[2][0] - shear[2]*row[1][0];
	row[2][1] = row[2][1] - shear[2]*row[1][1];
	row[2][2] = row[2][2] - shear[2]*row[1][2];
	scale[2] = vect_mag (row[2]);
	vect_normalize (row[2]);
	if (scale[2] != 0.0)
	{
		shear[1] /= scale[2];
		shear[2] /= scale[2];
	}
	vect_cross (temp, row[1], row[2]);
	if (vect_dot (row[0], temp) < 0.0)
	{
		for (i = 0; i < 3; i++)
		{
			scale[i]  *= -1.0;
			row[i][0] *= -1.0;
			row[i][1] *= -1.0;
			row[i][2] *= -1.0;
		}
	}
	if (row[0][2] < -1.0)
		row[0][2] = -1.0;
	if (row[0][2] > +1.0)
		row[0][2] = +1.0;
	rotate[1] = asin(-row[0][2]);
	rotate[0] = atan2 (row[1][2], row[2][2]);
	rotate[2] = atan2 (row[0][1], row[0][0]);
	/* Convert rotations to degrees */
	rotate[0] = (180.0/M_PI)*rotate[0];
	rotate[1] = (180.0/M_PI)*rotate[1];
	rotate[2] = (180.0/M_PI)*rotate[2];
	if(rotate[0] < 0.0)
		rotate[0] += 360.0;
	if(rotate[1] < 0.0)
		rotate[1] += 360.0;
	if(rotate[2] < 0.0)
		rotate[2] += 360.0;
}
>Hi All,
>
>I'm currently in the process of writing a Povray to Moray Parser, most of
>the objects can be imported and csg's, I have a few things to sort out like
>textures and declare statements. However my biggest problem is how I convert
>Povray object vectors to Moray Scale/Rotate/Translate vectors e.g. for a
>cone...
>// How do I convert from this (Pov format)......
>cone
>{
> <-2,-1,1>, 4,
> <5,-6,4>, 2
>  scale <0.5,0.5,0.5>
>  rotate <12,36,8>
>  translate  <-5,-1,1>
>}
>
>// to this (Moray format)......
>cone {
>  <0,0,0>, 4,
>  <0,0,1>, 2
>//  scale <x,y,z>
>//  rotate <x,y,z>
>//  translate  <x,y,z>
>}
>I can't change the base/cap vectors only the scale/rotate/translate vectors.
>Does anybody have any ideas? For the translate I assume I can add the base
>vector and the cone translate to get a Moray translation vector, but I'm
>stumpted on the scale and rotate vectors.
>
>Any help would be appriciated.....
>
>Many Thanks,
>
>Keith
>
>BTW is this the best place to post this....... maybe it should have gone to
>Pov programming?
>
> Post a reply to this message
 |  |